#include<iostream>
#include<vector>

using namespace std;


void mergesort(vector<int>& nums, int left, int right)
{
    if (left >= right) return;

    int mid = (left + right) >> 1;
    mergesort(nums, left, mid);
    mergesort(nums, mid+1, right);

    int cur1 = left, cur2 = mid, i = 0;
    vector<int> tmp;
    while (cur1 <= mid&& cur2 < right)
        tmp[i++] = nums[cur1] > nums[cur2] ? nums[cur1++] : nums[cur2];
    while (cur1 < mid) tmp[i++] = nums[cur1];
    while (cur2 < mid) tmp[i++] = nums[cur2];

    for (int j = 0; j < i; j++)
    {
        nums[left] = tmp[j++];
    }
}


vector<int> sortArray(vector<int>& nums) {
    mergesort(nums, 0, nums.size() - 1);
    return nums;
}

int main()
{
    vector<int> nums = { 5,2,3,1 };

    sortArray(nums);

    return 0;
}